import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mobile_vpn/pages/set_up/set_logic.dart';
import '../../common/cpn/cpn_view_state.dart';
import '../../theme/color_palettes.dart';

class AcceleratedModePage extends CpnViewState<SetLogic> {

 RxString selectedMode = '安全模式'.obs;
  @override
  AppBar? buildAppBar() {
    return AppBar(
      title: Text(
        '加速模式',
        style: TextStyle(
          color: ColorPalettes.instance.firstText,
          fontSize: 20,
          fontWeight: FontWeight.bold,
        ),
      ),
      centerTitle: true,
      iconTheme: IconThemeData(
        color: ColorPalettes.instance.firstText,
      ),
      backgroundColor: ColorPalettes.instance.background,
      elevation: 0, // 去除AppBar阴影
    );
  }
  @override
  Widget buildBody(BuildContext context) {
    return  SingleChildScrollView(
        padding: EdgeInsets.all(20.w),
        child: Column(
          children: [
            _buildSpeedModeItem(
              icon: Icons.balance,
              title: '平衡模式',
              description: '速度与安全兼顾，适合大多数场景',
              isSelected: selectedMode.value == '平衡模式',
              onTap: () {
                selectedMode.value='平衡模式';
              },
            ),

            SizedBox(height: 20.h),
            _buildSpeedModeItem(
              icon: Icons.rocket_launch,
              title: '极速模式',
              description: '优先速度，适合日常浏览和视频播放',
              isSelected: selectedMode.value == '极速模式',
              onTap: () {
                selectedMode.value='极速模式';
              },
            ),
            SizedBox(height: 20.h),
            _buildSpeedModeItem(
              icon: Icons.security,
              title: '安全模式',
              description: '优先安全，适合敏感数据传输',
              isSelected: selectedMode.value == '安全模式',
              onTap: () {
               selectedMode.value='安全模式';
              },
            ),
          ],
        ),
      );

  }

  // 构建加速模式选项
  Widget _buildSpeedModeItem({
    required IconData icon,
    required String title,
    required String description,
    required bool isSelected,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(vertical:  16.h, horizontal: 20.w),
        decoration: BoxDecoration(
          color: ColorPalettes.instance.background,
          borderRadius: BorderRadius.circular(10.r),
          border: isSelected
              ? Border.all(
            color: ColorPalettes.instance.primary,
            width: 2.w,
          )
              : null,
        ),
        child: Row(
          children: [
            Icon(
              icon,
              color: isSelected
                  ? ColorPalettes.instance.primary
                  : ColorPalettes.instance.secondText,
              size: 24,
            ),
            SizedBox(width: 16.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: TextStyle(
                      fontSize: 18,
                      color: ColorPalettes.instance.firstText,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  SizedBox(height: 4.h),
                  Text(
                    description,
                    style: TextStyle(
                      fontSize: 14,
                      color: ColorPalettes.instance.secondText,
                    ),
                  ),
                ],
              ),
            ),
            if (isSelected)
              Icon(
                Icons.check_circle,
                color: ColorPalettes.instance.primary,
                size: 24,
              ),
          ],
        ),
      ),
    );
  }


}